package com.zpark.drug.filter;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author Daimingdong
 * @version 1.0.0
 * @title LoginInterceptor
 * @create 2024/6/11 19:41
 * @description
 */
@Component
public class LoginInterceptor  implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 检查用户是否已登录的逻辑
        Object user = request.getSession().getAttribute("user");
        if (user == null) {
            // 未登录，重定向到登录页面
            response.sendRedirect("/login");
            return false;
        }
        // 已登录，放行请求
        return true;
    }
}
